package com.pb.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pb.mapper.ScoreMapper;
import com.pb.pojo.PageResult;
import com.pb.pojo.Score;
import com.pb.pojo.Subject;
import com.pb.service.ScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;
    @Override
    public void save(Score score) {
        //System.out.println(score.getModuleNo());
        scoreMapper.insert(score);
    }

    @Override
    public PageResult page(String studentName, String moduleName,Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<Score> dataList = scoreMapper.list(studentName,moduleName);
        Page<Score> p = (Page<Score>) dataList;

        return new PageResult(p.getTotal(), p.getResult());
    }

    @Override
    public Score getInfo(Integer id) {
        return scoreMapper.getInfo(id);
    }

    @Override
    public void update(Score score) {
        scoreMapper.update(score);
    }

    @Override
    public void deleteById(Integer id) {
        scoreMapper.deleteById(id);
    }

    @Override
    public List<Score> findAll() {
        return scoreMapper.findAll();
    }
}
